import * as THREE from "three";
import axios from "axios" ;
export const FourExp = {
	methods:{
		async fourExp(){
			this.loading = true
			this.$parent.btnIsDis = true;

			this.getMapData("worldMap") ;
			// 更换画框贴图
			var picArr = [
				{imgUrl:"img/relatedPhoto/Four/Poland1.jpg",imgDesc:"捷克共和国、匈牙利和波兰庆祝加入北约10周年，从左至右:北约捷克共和国常驻代表Stefan Fule、北约匈牙利常任代表Zoltan Martinusz和北约波兰常任代表Boguslaw Winid。"},
				{imgUrl:"img/relatedPhoto/Four/Poland2.jpg",imgDesc:"盟国加强北约在波罗的海国家、波兰、罗马尼亚的空中警务职责，皮兰Mig-29、美国F15和英国台风喷气式战斗机。"},
				{imgUrl:"img/relatedPhoto/Four/Poland3.jpg",imgDesc:"2014年4月29日，巴戈特维尔第425战术战斗机中队的加拿大武装部队成员在魁北克巴戈特维尔登上一艘CC-150 Polaris油轮前往罗马尼亚，这是加拿大为促进安全而采取的北约保证措施的一部分东欧和中欧的稳定。"}
			]
			this.changePicTexture(picArr);
			await this.loadCountryNumber(4);
			var flagAnimation,fontAnimation,arrowAnimation,firstDateAnimation,logoAnimation;
			var newCameraPos, newTargetPos;
			var Group  = new THREE.Group();
			Group.name = "Jb"
			var resource = new THREE.Group();
			this.scene.add(Group)


			// 日期模型
			var firstDate = this.gltfLoadModel("model/date/1991_12_25/scene.gltf")
			await firstDate.then((res) => {
				let font  =  res.scene ;
				font.scale.set(10, 10, 10) ;
				firstDateAnimation = res.animations[0] ;
				font.name="19911225"
				resource.add(font)
			})


			// 加载资源
			let CzechLabel 	   = this.get3dLabel("捷克共和国",false) ;
			var flagCzechModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagCzechTexture = this.changeTexture("img/flag/Czech.png") ;
			await flagCzechModel.then((res)=>{
				let flag = res.scene.clone();
				flagAnimation = res.animations[0];
				flag.name = "Czech";
				flag.scale.set(4, 4, 4)
				flag.children[0].children[1].material.map = flagCzechTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(CzechLabel)
				resource.add(flag)
			})

			// 加载资源
			let SvLabel   = this.get3dLabel("苏维埃社会主义共和国联盟",false) ;
			var SvModel   = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var SvTexture = this.changeTexture("img/flag/Soviet Union.png") ;
			await SvModel.then((res)=>{
				let flag = res.scene.clone();
				flagAnimation = res.animations[0];
				flag.name = "Sv";
				flag.scale.set(4, 4, 4)
				flag.children[0].children[1].material.map = SvTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(SvLabel)
				resource.add(flag)
			})

			let HungaryLabel 	   = this.get3dLabel("匈牙利",false) ;
			var flagHungaryModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagHungaryTexture = this.changeTexture("img/flag/Hungary.png") ;
			await flagHungaryModel.then((res)=>{
				let flag = res.scene.clone();
				flag.name = "Hungary";
				flag.scale.set(4, 4, 4)
				// 更换材质
				flag.children[0].children[1].material.map = flagHungaryTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(HungaryLabel)
				resource.add(flag)
			})

			let PolandLabel 	   = this.get3dLabel("波兰",false) ;
			var flagPolandModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagPolandTexture = this.changeTexture("img/flag/Poland.png") ;
			await flagPolandModel.then((res)=>{
				let flag = res.scene.clone();
				flag.name = "Poland";
				flag.scale.set(4, 4, 4)
				// 更换材质
				flag.children[0].children[1].material.map = flagPolandTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(PolandLabel)
				resource.add(flag)
			})


			let RussiaLabel 	   = this.get3dLabel("俄罗斯",false) ;
			var flagRussiaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagRussiaTexture = this.changeTexture("img/flag/Russia.png") ;
			await flagRussiaModel.then((res)=>{
				let flag = res.scene.clone();
				flag.name = "Russia";
				flag.scale.set(4, 4, 4)
				// 更换材质
				flag.children[0].children[1].material.map = flagRussiaTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(RussiaLabel)
				resource.add(flag)
			})

			var fourExpDate = this.gltfLoadModel("model/date/4-19990312/scene.gltf")
			await fourExpDate.then((res) => {
				let font  =  res.scene ;
				font.scale.set(10, 10, 10) ;
				fontAnimation = res.animations[0] ;
				font.name="19990312"
				resource.add(font)
			})

			var rightArrow = this.gltfLoadModel("model/public/rightarrow/scene.gltf")
			await rightArrow.then((res) => {
				res.scene.scale.set(5, 5, 5) ;
				arrowAnimation = res.animations[0] ;
				let rightArrowTop  =  res.scene.clone() ;
				rightArrowTop.name = "rightArrowTop" ;
				resource.add(rightArrowTop) ;
				let rightArrowBottom  =  res.scene.clone() ;
				rightArrowBottom.name = "rightArrowBottom" ;
				resource.add(rightArrowBottom) ;
			})

			var wtoLabel = this.get3dLabel("华沙条约组织", false, "50px");
			var wtoLogoModel = this.gltfLoadModel("model/wto/wtoLogoGltf/scene.gltf");
			await wtoLogoModel.then((res) => {
				logoAnimation = res.animations[0];
				res.scene.position.set(100, 20, -50) ;
				res.scene.scale.set(1.8, 1.8, 1.8) ;
				wtoLabel.position.set(0, 8, 0) ;
				res.scene.add(wtoLabel);
				res.scene.name = "wtoLogo"
				resource.add(res.scene)
			})
     		// 加载完成
			this.loading = false

			//////////////////////脚本//////////////////////
			setTimeout(()=>{
				// 移动视角
				this.fourthPropText()
				let newCamPos = {x:84.47897983605054,y:90.04816048725965,z:145.0517351937051}
				let newTarPos = {x:114.60546036572711,y:4,z:-44.49789864318399}
				this.animateCamera(this.camera.position,this.controls.target,newCamPos,newTarPos,2000) ;

				var SvCountrys=["Russia","Ukraine","Belarus","Uzbekistan","Kazakhstan","Georgia","Azerbaijan","Lithuania","Moldova","Latvia","Kyrgyzstan","Tajikistan","Turkmenistan","Estonia","Armenia"]

				this.map.children.forEach((item) => {
					for(let i = 0;i < SvCountrys.length ; i++){
						if (item.properties.name == SvCountrys[i]) {
							item.children.forEach((area) => {
								if (area.type == "Mesh") {
									area.material.color.set('#ff0000')
								}
							})
						}
					}
				})
				// 苏联旗帜模型出现
				let SvFlag = resource.getObjectByName("Sv")
				SvFlag.position.set(150.848673730019456,9,-40.741660839248752) ;
				Group.add(SvFlag) ;
				this.onceActionPlay(flagAnimation,SvFlag) ;

				// 19911225日期模型出现
				let date = resource.getObjectByName("19911225") ;
				date.position.set(150.848673730019456,20,-90.741660839248752) ;
				this.onceActionPlay(firstDateAnimation,date)
				Group.add(date)

				let wtoLogo = resource.getObjectByName("wtoLogo");
				Group.add(wtoLogo);
				this.onceActionPlay(logoAnimation,wtoLogo)
			},500)

			setTimeout(()=>{
				// 苏联国旗消失
				let SvFlag = Group.getObjectByName("Sv");
				let newPos = {x:150.84867373001944,y:-40,z:-40.74166083924875}
				this.recedingModel(SvFlag,SvFlag.position,newPos,3000)

				// 俄罗斯国旗出现
				let flag = resource.getObjectByName("Russia");
				flag.position.set(60.848673730019456,9,-30.741660839248752)
				this.onceActionPlay(flagAnimation,flag)
				Group.add(flag)

				var SvCountrys=[,"Ukraine","Belarus","Uzbekistan","Kazakhstan","Georgia","Azerbaijan","Lithuania","Moldova","Latvia","Kyrgyzstan","Tajikistan","Turkmenistan","Estonia","Armenia"]

				this.map.children.forEach((item) => {
					for(let i = 0;i < SvCountrys.length ; i++){
						if (item.properties.name == SvCountrys[i]) {
							item.children.forEach((area) => {
								if (area.type == "Mesh") {
									area.material.color.set('#a4a19c')
								}
							})
						}
					}
				})

			},7000)

			// 华约解散
			setTimeout(()=>{
				console.log(Group)
				let wtoLogo = Group.getObjectByName("wtoLogo") ;
				let newPos = {x:100,y:-40,z:-50} ;
				this.recedingModel(wtoLogo,wtoLogo.position,newPos,3000)
				console.log(Group)
			},12000)


			// 前半段动画 前17s
			this.$refs.Lines.src = "music/lines/fourexp/4-0.mp3" ;
			this.$refs.Lines.play();


			// 后半段动画
			setTimeout(()=>{
				this.$refs.Lines.src = "music/lines/fourexp/4-1.mp3" ;
				this.$refs.Lines.play();

				newCameraPos = {
					x:44.05371158955621,
					y:49.7183957593336,
					z:89.33493998110953
				}
				newTargetPos = {
					x:30.907840314180675,
					y:9,
					z:-28.827719421315066
				}

				this.animateCamera(this.camera.position, this.controls.target, newCameraPos, newTargetPos, 3000)

				setTimeout(()=>{
					let font = resource.getObjectByName("19990312");
					font.position.set(30.907840314180675,20,-28.827719421315066)
					this.onceActionPlay(fontAnimation,font)
					Group.add(font)
				},500)

				setTimeout(()=>{
					let flag = resource.getObjectByName("Czech");
					flag.position.set(24.978684077760832,9,-23.25040092613881)
					this.onceActionPlay(flagAnimation,flag)
					Group.add(flag)
				},1000)
				setTimeout(()=>{
					let flag = resource.getObjectByName("Poland");
					flag.position.set(30.907840314180675,9,-28.827719421315066)
					this.onceActionPlay(flagAnimation,flag)
					Group.add(flag)
				},2000)
				setTimeout(()=>{
					let flag = resource.getObjectByName("Hungary");
					flag.position.set(30.848673730019456,9,-18.741660839248752)
					this.onceActionPlay(flagAnimation,flag)
					Group.add(flag)
				},3000)

				setTimeout(()=>{
					let rightArrowTop = resource.getObjectByName("rightArrowTop");
					rightArrowTop.rotateY(Math.PI / 2)
					rightArrowTop.position.set(40.848673730019456,9,-30.741660839248752)
					this.onceActionPlay(arrowAnimation,rightArrowTop)
					Group.add(rightArrowTop)

					let RightArrowBottom = resource.getObjectByName("rightArrowBottom");
					RightArrowBottom.rotateY(Math.PI / 2)
					RightArrowBottom.position.set(40.848673730019456,9,-10)
					this.onceActionPlay(arrowAnimation,RightArrowBottom)
					Group.add(RightArrowBottom)
				},11000)

				setTimeout(()=>{
					let newCameraPos = {
						x:-35.11177457306488,
						y:90.85025146474065,
						z:165.48315863596713
					}

					let newTargetPos = {
						x:7.927978551975201,
						y:52.54156385652676,
						z:60.34042900910805
					}

					this.animateCamera(this.camera.position, this.controls.target, newCameraPos, newTargetPos, 3000)
				},12000)
			},17000)
		}
	}
}